<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Car extends CI_Controller {
    function Car() {
        parent::__construct();
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index() {
        $this->db->where('type_id', 3);
        $data['dealer'] = $this->db->get('psacar_member');
        $data['type'] = $this->db->get('psacar_car_type');
        $data['make'] = $this->db->get('psacar_make');        
        $data['category'] = $this->db->get('psacar_category');	
        $data['drivetrain'] = $this->db->get('psacar_drivetrain');	
        $data['transmission'] = $this->db->get('psacar_transmission');	

        $this->db->order_by("order", "asc"); 
        $this->db->order_by("name", "asc"); 
        $data['part'] = $this->db->get('psacar_part');	
        
        $this->db->order_by("order", "asc"); 
        $this->db->order_by("name", "asc"); 
        $data['service'] = $this->db->get('psacar_service');        
        
        $data['car'] = $this->db->get('psacar_car');
        
        $this->db->order_by("order", "asc"); 
        $this->db->order_by("province", "asc"); 
        $data['location'] = $this->db->get('psacar_location');
        
        $this->db->order_by("color", "asc"); 
        $data['color'] = $this->db->get('psacar_color');

        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_advance', $data);
        $this->load->view('footer', $data);        
    }

    public function advance()
    {
        $data['message'] = "";

        $offset = $this->uri->segment(3);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;

        $cartype = $this->input->post('cartype');
        if(strlen($cartype) == 0)
            $cartype = '%';
        
        $make = $this->input->post('make');        
        $model = $this->input->post('model');
        $maxprice = intval($this->input->post('maxprice'));
        $location = $this->input->post('location');
        $dealer = $this->input->post('dealer');
        
        $price_range = $this->input->post('price_range');        
        $price_range_list = preg_split('/ - /', $price_range, -1, PREG_SPLIT_OFFSET_CAPTURE);
        $from_price = $price_range_list[0][0];
        $to_price = $price_range_list[1][0];
        
        $mileage_range = $this->input->post('mileage_range');        
        $mileage_range_list = preg_split('/ - /', $mileage_range, -1, PREG_SPLIT_OFFSET_CAPTURE);
        $from_mileage = $mileage_range_list[0][0];
        $to_mileage = $mileage_range_list[1][0];

        $year_range = $this->input->post('year_range');        
        $year_range_list = preg_split('/ - /', $year_range, -1, PREG_SPLIT_OFFSET_CAPTURE);
        $from_year = $year_range_list[0][0];
        $to_year = $year_range_list[1][0];

        $external_color = $this->input->post('external_color');        
        $drivetrain = $this->input->post('drivetrain');        
        $transmission = $this->input->post('transmission');
        
        $fuel = $this->input->post('fuel');        
        
        $data['criteria_list'] = 
            $this->register_search_criteria(                    
                $cartype, 
                $make, 
                $model, 
                $maxprice, 
                $location, 
                $dealer, 
                $price_range, 
                $mileage_range, 
                $year_range, 
                $external_color, 
                $drivetrain, 
                $transmission, 
                $fuel);
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_car_list_advance(
            $make, 
            $model, 
            $maxprice,
            $location,
            $dealer,
            $from_price,
            $to_price,
            $from_mileage,
            $to_mileage,
            $from_year,
            $to_year,
            $external_color,
            $drivetrain,
            $transmission,
            $fuel,
            $cartype);
        
        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/result',
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer',$data);
    }
    
    public function make()
    {				
        $data['message'] = "";
        
        $offset = $this->uri->segment(4);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;

        $make_name = $this->uri->segment(3);
        $make_name = str_replace("%20", " ", $make_name);
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_car_by_make($make_name);

        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/make/' . $make_name,
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;        
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result',$data);
        $data['make'] = $this->db->get('psacar_make');                        
        $this->load->view('footer',$data);
    }
    
    public function category()
    {	
        $data['message'] = "";        

        $offset = $this->uri->segment(4);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;

        $category_name = $this->uri->segment(3);
        $category_name = str_replace("%20", " ", $category_name);
                
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_car_by_category($category_name);

        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/category/' . $category_name,
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;        
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        $data['make'] = $this->db->get('psacar_make');
        $this->load->view('footer',$data);
    }  
    
    public function detail()
    {
        $data['message'] = "";

        //Variable
        $car_id = $this->uri->segment(3);
        
        //Query: Car list
        $this->load->model('Car_model');
        $data['car_list'] = $this->Car_model->get_car_by_id($car_id);
        
        //Query: Comment
        $this->load->model('Comment_model');
        $data['comment_list'] = $this->Comment_model->get_comments_by_car($car_id);	

        $this->load->view('header', $data);
        $this->load->view('templates/car/car_detail', $data);
        
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);
    }	
    
    public function buy() 
    {        
        $data['message'] = "";

        //Database
        $data['category']=$this->db->get('psacar_category');

        $this->db->where('type_id', 1);
        $data['dealer']= $this->db->get('psacar_member');
        
        $data['type']= $this->db->get('psacar_car_type');
        //$data['year']=$this->db->get('psacar_series');
        $data['make']= $this->db->get('psacar_make');
        $data['model']= $this->db->get('psacar_model');
        $data['car'] = $this->db->get('psacar_car');
        $data['location']=$this->db->get('psacar_location');
        
        //Query
        $this->db->group_by('year'); // Order by
        $this->db->group_by('price'); // Order by
        $this->load->model('Car_model');
                
        $this->load->view('header', $data);
        $this->load->view('car', $data);
        $this->load->view('footer', $data);
    }
    
    public function result()
    {
        $data['message'] = "";
        
        $offset = $this->uri->segment(3);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;
                
        $cartype = $this->input->post('cartype');
        if($cartype == '')
            $cartype = '%';
        
        $make = $this->input->post('make');
        $model = $this->input->post('model');
        $maxprice = intval($this->input->post('maxprice'));
        $year = $this->input->post('year');
        $location = $this->input->post('location');
        $dealer = $this->input->post('dealer');
        
        $data['criteria_list'] = 
            $this->register_search_criteria(                    
                $cartype, 
                $make, 
                $model, 
                $maxprice, 
                $location, 
                $dealer, 
                '', 
                '', 
                $year, 
                '', 
                '', 
                '', 
                '');
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_car_list(
            $make, 
            $model, 
            $maxprice, 
            $dealer,
            $year,
            $location,
            $cartype);

        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/result',
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);        
    }
    
    public function process()
    {		
        $email = $this->security->xss_clean($this->input->post('email'));
        $password = $this->security->xss_clean($this->input->post('password'));
         
        $this->load->model('Member_model');
        $this->Member_model->login($email, $password);
        if($this->session->userdata('validated'))
            $data['message'] = "";
        else
            $data['message'] = "<font color=red>Invalid username and/or password.</font>";
                                    
        $car_id = $this->uri->segment(3);
        if($car_id)
        {
            $this->load->model('Car_model');
            $data['car_list'] = $this->Car_model->get_car_by_id($car_id);

            $this->load->model('Comment_model');
            $data['comment_list'] = $this->Comment_model->get_comments_by_car($car_id);

            $this->load->view('header', $data);
            $this->load->view('templates/car/car_detail', $data);
            $data['make']= $this->db->get('psacar_make');
            $this->load->view('footer', $data);        
        }
        else 
            redirect(base_url() . 'index.php/car');
    }   
    
    public function submit() {        
        if ($this->session->userdata('validated')) {
            if ($this->session->userdata('membership') != 4) {
                //Serie
                $make = $this->input->post('make');
                $model = $this->input->post('model');
                $year = $this->input->post('year');
                $external_color = $this->input->post('external_color');

//                $serie_list = $this->db->get_where(
//                    'psacar_series', 
//                    array(
//                        'model_id' => $model,
//                        'color_id' => $external_color,
//                        'year' => $year
//                    ));

//                $serie_id = 0;                
//                foreach($serie_list->result() as $serie)
//                    $serie_id = $serie->id;
//
//                if($serie_id == 0)
//                {
//                    $serie =  array(
//                        'model_id' => $model,
//                        'color_id' => $external_color,
//                        'year' => $year,
//                        'created_date' => date("Y-m-d"),
//                        'modified_date' => date("Y-m-d"));
//                    $this->db->insert('psacar_series', $this->security->xss_clean($serie));
//                    $serie_id = $this->db->insert_id();
//                }                

                $all_fuel = '';
                if(is_array($this->input->post('fuel'))){
                    foreach ($this->input->post('fuel') as $a_fuel)
                        $all_fuel = $all_fuel . $a_fuel . ',';

                    if(substr($all_fuel, strlen(',') * -1) == ',')
                        $all_fuel = substr($all_fuel, 0, strlen($all_fuel) - 1);
                }

                //Process registration
                $this->load->database();                            
                $car = array(
                    'model_id' => $model,
                    'year' => $year,                    
                    'dealer_id' => $this->session->userdata('userid'),
                    'vehicle_id_number' => $this->input->post('vehicle_id_number'),
                    'image' => $this->input->post('userfile'),       
                    'external_color_id' => $external_color,
                    'fuel' => $all_fuel,
                    'post_date' => date("Y-m-d"),
                    'expiration_date' => date("Y-m-d"),
                    'status' => 0,
                    'post_by' => $this->session->userdata('userid'),
                    'created_date' => date("Y-m-d"),
                    'modified_date' => date("Y-m-d"));

                if(strlen($this->input->post('type')) != 0)
                    $car['type_id'] = $this->input->post('type');

                if(strlen($this->input->post('category')) != 0)
                    $car['category_id'] = $this->input->post('category');

                if(strlen($this->input->post('internal_color')) != 0)
                    $car['internal_color_id'] = $this->input->post('internal_color');

                if(strlen($this->input->post('transmission')) != 0)
                    $car['transmission'] = $this->input->post('transmission');
                
                if(strlen($this->input->post('drive_train')) != 0)
                    $car['drive_train'] = $this->input->post('drive_train');

                if(strlen($this->input->post('door_count')) != 0)
                    $car['door_count'] = $this->input->post('door_count');

                if(strlen($this->input->post('price')) != 0)
                    $car['price'] = $this->input->post('price');

                if(strlen($this->input->post('quality')) != 0)
                    $car['quality'] = $this->input->post('quality');

                //Features
                //Comfort
                $feature_comfort = '';
                if(is_array($this->input->post('feature_comfort'))){
                    $feature_comfort = '<div id="car_feature" class="car_feature">';
                    $feature_comfort .= '<ul>';
                    foreach ($this->input->post('feature_comfort') as $feature)
                    {
                        $feature_comfort .= '<li>';
                        $feature_comfort .= $feature;
                        $feature_comfort .= '</li>';
                    }
                    $feature_comfort .= '</ul>';
                    $feature_comfort .= '</div>';
                }

                //Safety
                $feature_safety = '';
                if(is_array($this->input->post('feature_safety'))){
                    $feature_safety = '<div id="car_feature" class="car_feature">';
                    $feature_safety .= '<ul>';
                    foreach ($this->input->post('feature_safety') as $feature)
                    {
                        $feature_safety .= '<li>';
                        $feature_safety .= $feature;
                        $feature_safety .= '</li>';
                    }
                    $feature_safety .= '</ul>';
                    $feature_safety .= '</div>';
                }

                //Windows
                $feature_window = '';
                if(is_array($this->input->post('feature_window'))){
                    $feature_window = '<div id="car_feature" class="car_feature">';
                    $feature_window .= '<ul>';
                    foreach ($this->input->post('feature_window') as $feature)
                    {
                        $feature_window .= '<li>';
                        $feature_window .= $feature;
                        $feature_window .= '</li>';
                    }
                    $feature_window .= '</ul>';
                    $feature_window .= '</div>';
                }

                //Seats
                $feature_seat = '';
                if(is_array($this->input->post('feature_seat'))){
                    $feature_seat = '<div id="car_feature" class="car_feature">';
                    $feature_seat .= '<ul>';
                    foreach ($this->input->post('feature_seat') as $feature)
                    {
                        $feature_seat .= '<li>';
                        $feature_seat .= $feature;
                        $feature_seat .= '</li>';
                    }
                    $feature_seat .= '</ul>';
                    $feature_seat .= '</div>';
                }

                //Sound System
                $feature_sound = '';
                if(is_array($this->input->post('feature_sound'))){
                    $feature_sound = '<div id="car_feature" class="car_feature">';
                    $feature_sound .= '<ul>';
                    foreach ($this->input->post('feature_sound') as $feature)
                    {
                        $feature_sound .= '<li>';
                        $feature_sound .= $feature;
                        $feature_sound .= '</li>';
                    }
                    $feature_sound .= '</ul>';
                    $feature_sound .= '</div>';
                }

                //Other
                $feature_other = '';
                if(is_array($this->input->post('feature_other'))){
                    $feature_other = '<div id="car_feature" class="car_feature">';
                    $feature_other .= '<ul>';
                    foreach ($this->input->post('feature_other') as $feature)
                    {
                        $feature_other .= '<li>';
                        $feature_other .= $feature;
                        $feature_other .= '</li>';
                    }
                    $feature_other .= '</ul>';
                    $feature_other .= '</div>';
                }

                $car['description'] = 
                    "<strong>Features:</strong>" . 
                    $feature_comfort .
                    $feature_safety . 
                    $feature_window .
                    $feature_seat . 
                    $feature_sound . 
                    $feature_other . 
                    $this->input->post('description');

                $this->db->insert('psacar_car', $this->security->xss_clean($car));
                $car_id = $this->db->insert_id();
                
                //Reference number
                $car_code = '';
                $type_code_list = $this->db->get_where(
                    'psacar_car_type', 
                    array('id' => $car['type_id']));
                if ($type_code_list->num_rows != 0) {
                    $type_code = $type_code_list->row();
                    $car_code = $type_code->short_code;
                }

                $car_code .= 
                    substr('00000' . $car_id, -5) . 
                    random_string('alnum', 3);
                $data['code'] = $car_code;

                $this->db->where('id', $car_id);
                $this->db->update('psacar_car', $data);

                //Car images
                $this->upload_images($car_id);
                
                $data["message_title"] = "Car registered";
                $data["message_body"] = 
                    "Thank you for listing with <a href='" . base_url() . "'>www.psacar.com.</a> Your listing will appear online once it has been approved by our admin team.";
            }
            else {
                $data["message_title"] = "Access denied";
                $data["message_body"] = "With the current role, you are not allowed to list any car.";
            }
        }
        else {
            $data["message_title"] = "Authentication failure";
            $data["message_body"] = "Please login to list any car.";
        }
        
        $this->load->view('header', $data);
        $this->load->view('information', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);            
    }
    
    private function upload_images($car_id = 0)
    {        
        $config['upload_path'] = './system/public/assets/cars/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2048';
        $config['max_width'] = '1024';
        $config['max_height'] = '1024';
        $config['encrypt_name'] = true;
        $config['remove_spaces'] = true;

        $this->load->library('upload', $config);
        $upload_result = $this->upload->do_multi_upload();
        
        if(is_array($upload_result)) {
            foreach($upload_result as $upload => $file) {                
                $car_image = array(
                    'car_id' => $car_id,
                    'image' => $file['file_name']
                );

                $this->db->insert('psacar_car_image', $this->security->xss_clean($car_image));                
            }
        }
    }
    
    public function extend()
    {        
        $date = new DateTime(date('Y-m-d'));
        $date->add(new DateInterval('P30D'));            

        $car_id = $this->uri->segment(3);
        if($car_id) {
            $data["expiration_date"] = $date->format("Y-m-d");
            $this->db->where('id', $car_id);
            $this->db->update('psacar_car', $data);
        }
        
        $data["message_title"] = "Car listing";
        $data["message_body"] = "Your car is listed at <a href='" . base_url() . "'>www.psacar.com</a> until " . $date->format("Y-m-d") . ".";
        $this->load->view('header', $data);
        $this->load->view('information', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);            
   }
    
    public function delete()
    {
        $car_id = $this->uri->segment(3);
        if($car_id) {
            $data["status"] = 2;
            $this->db->where('id', $car_id);
            $this->db->update('psacar_car', $data);
        }
        
        $data["message_title"] = "Car deletion";
        $data["message_body"] = "Your car has been successfully removed from listing of <a href='" . base_url() . "'>www.psacar.com</a>";
        $this->load->view('header', $data);
        $this->load->view('information', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);
   }    
   
    public function register()
    {   
        if ((!$this->session->userdata('validated')) ||
            ($this->session->userdata('membership') == 4)) {            
            redirect(base_url().'index.php/sell');
        }
        else
        {
            $data['make']= $this->db->get('psacar_make');
            $data['model']= $this->db->get('psacar_model');
            $data['location'] = $this->db->get('psacar_location');
            $data['category'] = $this->db->get('psacar_category');
            $this->db->order_by('color', 'asc');
            $this->db->where('category_id', 1);
            $data['color_internal'] = $this->db->get('psacar_color');	
            $this->db->order_by('color', 'asc');
            $this->db->where('category_id', 2);
            $data['color_external'] = $this->db->get('psacar_color');	
            $data['type'] = $this->db->get('psacar_car_type');	
            $data['fuel'] = $this->db->get('psacar_fuel');
            $data['transmission'] = $this->db->get('psacar_transmission');
            $data['drivetrain'] = $this->db->get('psacar_drivetrain');

            $this->load->model('Serie_model');
            $data['serie'] = $this->Serie_model->get_series();

            $this->load->view('header', $data);
            $this->load->view('templates/car/car_register', $data);        
            $this->load->view('footer', $data);
        }
    }     
    
    public function listed() {
        $data['message'] = "";

        $offset = $this->uri->segment(4);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;
        
        $member_id = $this->uri->segment(3);
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_approved_car_by_member_id($member_id);
        
        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/pending/' . $member_id,
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer',$data);         
    } 
   
    public function pending() {
         $data['message'] = "";

        $offset = $this->uri->segment(4);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;
                
        $member_id = $this->uri->segment(3);
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_pending_car_by_member_id($member_id);
        
        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/pending/' . $member_id,
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer',$data);                 
    }

    public function expired() {
        $data['message'] = "";

        $offset = $this->uri->segment(4);
        if(strlen($offset) == 0)
            $offset = 0;
        
        $limit = $this->input->post('limit');
        if(strlen($limit) == 0)
            $limit = 10;
                
        $member_id = $this->uri->segment(3);
        
        $this->load->model('Car_model');
        $car_list = $this->Car_model->get_expired_car_by_member_id($member_id);
        
        //Pagination
        $data['pagination'] = $this->generate_pagination(
            'index.php/car/pending/' . $member_id,
            $car_list->num_rows,
            $limit);
        
        $car_list = array_slice($car_list->result(), $offset, $limit);        
        $data['car_list'] = $car_list;
        $this->load->view('header', $data);
        $this->load->view('templates/car/car_search_result', $data);
        $data['make']= $this->db->get('psacar_make');
        $this->load->view('footer', $data);        
    }
    
    public function review() {
    }    
    
    public function register_search_criteria(
        $cartype = '%',
        $make = '',
        $model = '',
        $maxprice = '',
        $location = '',
        $dealer = '',
        $price_range = '',
        $mileage_range = '',
        $year_range = '',
        $external_color = '',
        $drivetrain = '',
        $transmission = '',
        $fuel = '',
        $category = '') {
        
        $search_critieria = array(
            array(
                'field' => 'cartype',
                'value' => $cartype),
            array(
                'field' => 'make',
                'value' => $make),
            array(
                'field' => 'model',
                'value' => $model),
            array(
                'field' => 'maxprice',
                'value' => intval($maxprice)),
            array(
                'field' => 'location',
                'value' => $location),
            array(
                'field' => 'dealer',
                'value' => $dealer),
            array(
                'field' => 'price_range',
                'value' => $price_range),
            array(
                'field' => 'mileage_range',
                'value' => $mileage_range),
            array(
                'field' => 'year_range',
                'value' => $year_range),
            array(
                'field' => 'transmission',
                'value' => $transmission),
            array(
                'field' => 'fuel',
                'value' => $fuel),            
        );

        return $search_critieria;
    }
    
    public function generate_pagination($base_url = '', $total_row = 0, $per_page = 0) {
        //echo $per_page;
        $this->load->library('pagination');
        $config['base_url'] = base_url() . $base_url;
        $config['total_rows'] = $total_row;
        $config['per_page'] = $per_page;

        $limiter = '<select name="limit">';
        for($counter = 10; $counter <= 100; ) {
            $limiter .= 
                '<option value="' . $counter . '" ' . 
                ($per_page == $counter ? 'selected' : '') . 
                '>' . $counter . ' per page</option>';
            $counter += 10;
        }
        $limiter .= "</select> | ";
                
        $config['full_tag_open'] = '<div class="pagination">' . $limiter;
        $config['full_tag_close'] = '</div>';
        $this->pagination->initialize($config);
        return $this->pagination->create_links();
    }
}